package DataStructure;

import util.Point;
import util.Polynomial;

import java.math.BigInteger;
import java.util.Random;

/**
 * 表示一个棵树中的节点
 * 该树在此特化为一个CPABE算法策略树中的节点
 */
public class TreeNode {
    //TODO-pht:将树节点抽象成泛型，方便后续作为基本的数据结构库使用

    //多项式
    private Polynomial polynomial;
    //节点的阶
    private int order;
    //节点的门限值
    private int threshold;
    //孩子节点的编号
    private int[] children;
    //父节点的编号
    private  int parent;
    //该节点的编号
    private int nodeIndex;
    //节点的属性值
    private String attribute;
    //标签,在算法中使用
    private int index;
    //该节点是否遍历过
    private boolean viewed;

    /**
     * 初始化部分必选值的构造函数
     * @param order 节点的阶，即孩子节点的数量
     * @param threshold 节点的门限值
     * @param nodeIndex 该节点在树中的编号
     * @param polynomial 该节点包含的多项式
     */
    public TreeNode(int order,int threshold,int nodeIndex,Polynomial polynomial){
        this.polynomial=polynomial;
        this.threshold=threshold;
        this.order=order;
        this.nodeIndex=nodeIndex;
        children=new int[order];
        viewed=false;
    }

    public TreeNode(){

    }

    public String toString(){
        StringBuilder builder=new StringBuilder();
        builder.append(order);
        builder.append("@");
        builder.append(threshold);
        builder.append("@");
        for (int i = 0; i < children.length; i++) {
            builder.append(children[i]);
            builder.append("#");
        }
        builder.append(parent);
        builder.append("@");
        builder.append(nodeIndex);
        builder.append("@");
        builder.append(attribute);
        builder.append("@");
        builder.append(index);
        return builder.toString();

    }

    public void setPolynomial(Polynomial polynomial) {
        this.polynomial = polynomial;
    }

    public void setOrder(int order) {
        this.order = order;
    }

    public void setThreshold(int threshold) {
        this.threshold = threshold;
    }

    public void setChildren(int[] children) {
        this.children = children;
    }

    public void setParent(int parent) {
        this.parent = parent;
    }

    public void setNodeIndex(int nodeIndex) {
        this.nodeIndex = nodeIndex;
    }

    public void setAttribute(String attribute) {
        this.attribute = attribute;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public Polynomial getPolynomial() {
        return polynomial;
    }

    public int getOrder() {
        return order;
    }

    public int getThreshold() {
        return threshold;
    }

    public int[] getChildren() {
        return children;
    }

    public int getParent() {
        return parent;
    }

    public int getNodeIndex() {
        return nodeIndex;
    }

    public String getAttribute() {
        return attribute;
    }

    public int getIndex() {
        return index;
    }

    public boolean getViewed() {
        return viewed;
    }

    public void setViewed(boolean viewed) {
        this.viewed = viewed;
    }


    /**
     * 清空树节点中的多项式
     */
    public void clearPoly(){
        polynomial=null;
    }
}
